package com.breakfast.fun.ui.mall;

import com.breakfast.fun.data.entity.mall.MallBanner;
import com.breakfast.fun.util.T;

import java.util.HashMap;
import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by yukai on 16/10/1.
 */

public class ToolPresenter extends ToolContract.Presenter {
    @Override
    public void onStart() {
        getTool();
    }


    @Override
    public void getTool() {
        Map<String, String> map = new HashMap<>();

        map.put("action", "GetShopBanner");

        rxManager.add(model.getToolBannerModel(map)
                .subscribeOn(Schedulers.computation())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new Subscriber<MallBanner>() {
                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        T.show("获取数据失败");
                    }

                    @Override
                    public void onNext(MallBanner mallBanner) {
                        if (mallBanner.isSuccess()) {
                            view.showTool(mallBanner);
                        } else {
                            T.show(mallBanner.getMsg());
                        }
                    }

                }));
    }
}
